package org.tiger.service.datasource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.alibaba.druid.pool.DruidDataSource;

@Configuration
//这个注解导入刚才增加的jdbc配置文件
@PropertySource("classpath:application.properties")
public class DataSourceConfiguration {
  @Value("${jdbc.driver}")
  private String driver;
  @Value("${jdbc.url}")
  private String url;
  @Value("${jdbc.username}")
  private String username;
  @Value("${jdbc.password}")
  private String password;
  @Value("${jdbc.maxActive}")
  private int maxActive;
  @Value("${jdbc.maxIdel}")
  private int maxIdel;
  @Value("${jdbc.maxWait}")
  private long maxWait;

  
  @Bean
  public DruidDataSource dataSource(){
	  DruidDataSource dataSource = new DruidDataSource();
      dataSource.setDriverClassName(driver);
      dataSource.setUrl(url);
      dataSource.setUsername(username);
      dataSource.setPassword(password);
      dataSource.setMaxActive(maxActive);
      dataSource.setMaxWait(maxWait);
      dataSource.setValidationQuery("SELECT 1");
      dataSource.setTestOnBorrow(true);
      return dataSource;
  }
}